//
//  Tools.m
//  Baby
//
//  Created by YC on 2017/8/8.
//  Copyright © 2017年 YC. All rights reserved.
//

#import "Tools.h"

@implementation Tools

+ (BOOL)whetherTheSameDay:(NSDate *)date1 date2:(NSDate *)date2 {
    if (date1 != nil && date2 != nil) {
        NSCalendar *cal = [NSCalendar currentCalendar];
        
        NSDateComponents *components = [cal components:(NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit) fromDate:date1];
        NSDate *today = [cal dateFromComponents:components];
        
        components = [cal components:(NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit) fromDate:date2];
        
        NSDate *otherDate = [cal dateFromComponents:components];
        
        if([today isEqualToDate:otherDate]){
            return YES;
        }
    }
    
    return NO;
}

+ (void)save {
    [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
}

@end
